#include<stdio.h>

char p[]={'a','b','a','b','a','a',' '};
int b[sizeof(p)];


void KMPPreprocess()
{
	int i=0,j=-1;
	b[i]=j;

	while(i<sizeof(p))
	{
		while(j>=0&&p[i]!=p[j])
			j = b[j];
		i++;
		j++;
		b[i]=j;
	}

	for(i=0;i<sizeof(p);i++)
	{
		printf("%d\t",b[i]);
	}

	printf("\n");
}

int main() 
{ 
	KMPPreprocess();
	return 0; 
} 
